package com.minivision.sdktestdemo.theme.ui;

import android.content.Context;
import android.content.res.Resources;
import android.util.AttributeSet;
import android.view.View;
import android.widget.Button;

import com.minivision.sdktestdemo.theme.utils.CustomThemeInterface;
import com.minivision.sdktestdemo.theme.utils.ViewAttributeUtils;

/**
 * Created by Administrator on 2016/6/21.
 */
public class CustomThemeButton extends Button implements CustomThemeInterface {
    private int attrBackGroundColor = -1;
    private int attrTextColor = -1;

    public CustomThemeButton(Context context) {
        super(context);
    }

    public CustomThemeButton(Context context, AttributeSet attrs) {
        super(context, attrs);
        attrBackGroundColor = ViewAttributeUtils.getBackgroundAttribute(attrs);
        attrTextColor = ViewAttributeUtils.getTextColorAttribute(attrs);
    }

    public CustomThemeButton(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        attrBackGroundColor = ViewAttributeUtils.getBackgroundAttribute(attrs);
        attrTextColor = ViewAttributeUtils.getTextColorAttribute(attrs);
    }

    @Override
    public View getView() {
        return this;
    }

    @Override
    public void setTheme(Resources.Theme themeId) {
        if (attrBackGroundColor != -1) {
            ViewAttributeUtils.applyBackgroundDrawable(this, themeId, attrBackGroundColor);
        }
        if (attrTextColor != -1) {
            ViewAttributeUtils.applyTextColor(this, themeId, attrTextColor);
        }
    }
}
